#include "nr_xmlTomongodb_test.h"

#include "nr_io_xml.h"

nr_xmlTomongodb_test::nr_xmlTomongodb_test()
    :m_xml_io(NULL)
    ,m_mongodb_io(NULL)
{
    m_xml_io = nr_io_factory::create( nr_io_factory::NR_IO_TYPE_XML );
    Q_ASSERT(m_xml_io);
    m_mongodb_io = nr_io_factory::create( nr_io_factory::NR_IO_TYPE_MONGODB );
    Q_ASSERT(m_xml_io);

    nr_error_t status;
    status = m_xml_io->connect();
    Q_ASSERT(NR_SUCCEED(status));
    qDebug() << "XML io is connected";

    m_mongodb_io->host() = "localhost";
    status = m_mongodb_io->connect();
    Q_ASSERT(NR_SUCCEED(status));
    qDebug() << "MongoDB io is connected";
}

nr_xmlTomongodb_test::~nr_xmlTomongodb_test()
{
    
}

void nr_xmlTomongodb_test::run()
{
    m_xml_io->read_device_types(m_device_types);
    qDebug() << "read device types from xml...done";
    m_xml_io->read_device_items(m_device_item_server);
    qDebug() << "read device itms from xml...done";

    m_mongodb_io->write_device_types(m_device_types);
    qDebug() << "write device types to mongoDB...done";
    m_mongodb_io->write_device_items(m_device_item_server);
    qDebug() << "write device itms to mongoDB...done";
}

void nr_xmlTomongodb_test::validate()
{
    m_mongodb_io->read_device_types(m_device_types);
    qDebug() << "read device types from mongoDB...done";
    m_mongodb_io->read_device_items(m_device_item_server);
    qDebug() << "read device items from mongoDB...done";

    nr_io_xml *ptr = (nr_io_xml*)m_xml_io;
    ptr->set_DeviceTypeFile("\\DeviceSchema_2.xml");
    ptr->set_DeviceItemsFile("\\DeviceItems_2.xml");
    m_xml_io->write_device_types(m_device_types);
    qDebug() << "write device types to xml as \"DeviceSchema_2.xml\"file...done";
    m_xml_io->write_device_items(m_device_item_server);
    qDebug() << "write device items to xml as \"DeviceSchema_2.xml\"file...done";
}

